import * as THREE from 'three'
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader"

//创建场景对象
const scene = new THREE.Scene()

//创建相机对象 PerspectiveCamera:透视相机
const camera = new THREE.PerspectiveCamera(
  75, //角度
  window.innerWidth / window.innerHeight, //宽高比
  0.1, // 近切面
  1000 // 远切面
)

// 创建渲染器对象
const renderer = new THREE.WebGLRenderer({
  antialias: true //消除锯齿边缘
})
//设置尺寸
renderer.setSize(window.innerWidth, window.innerHeight)
//开启投影
renderer.shadowMap.enabled = true

//添加到dom中
document.body.appendChild(renderer.domElement)

//添加光源
const ambientLight = new THREE.AmbientLight(0xffffff)
scene.add(ambientLight)
const directionLight = new THREE.DirectionalLight(0xffffff, 2.5)
directionLight.castShadow = true //开启投影
directionLight.position.set(20, 20, 30)
scene.add(directionLight)

//加载fbx的方法
export const loadFbx = (url) => {
  const fbxLoader = new FBXLoader()
  return new Promise(resolve => {
    fbxLoader.load(url, (object) => {
      resolve(object)
    })
  })
}

export { scene, camera, renderer }